package org.qpcr.community.standalone.web.response.dashboard;

import lombok.Data;

import java.util.List;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;

@Data
public class AlarmConfigCountResp {
    private List<String> xdata;
    private List<ConfigSeries> series;

    /**
     * 根据periodType生成mock数据，periodType支持：today、week、month
     */
    public static AlarmConfigCountResp createMockData(String periodType) {
        AlarmConfigCountResp resp = new AlarmConfigCountResp();
        List<String> xdata = new ArrayList<>();
        List<ConfigSeries> seriesList = new ArrayList<>();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM-dd");
        LocalDate today = LocalDate.now();
        int days = 1;
        if ("week".equalsIgnoreCase(periodType)) {
            days = 7;
        } else if ("month".equalsIgnoreCase(periodType)) {
            days = 30;
        }
        for (int i = days - 1; i >= 0; i--) {
            xdata.add(today.minusDays(i).format(formatter));
        }
        // mock两组series
        ConfigSeries s1 = new ConfigSeries();
        s1.setName("属性上报告警");
        s1.setColor("#2066F9");
        List<Integer> data1 = new ArrayList<>();
        ConfigSeries s2 = new ConfigSeries();
        s2.setName("设备离线告警");
        s2.setColor("#FF7B8A");
        List<Integer> data2 = new ArrayList<>();
        for (int i = 0; i < days; i++) {
            data1.add(10 + (int)(Math.random() * 10)); // 10~19
            data2.add(5 + (int)(Math.random() * 6));   // 5~10
        }
        s1.setData(data1);
        s2.setData(data2);
        seriesList.add(s1);
        seriesList.add(s2);
        resp.setXdata(xdata);
        resp.setSeries(seriesList);
        return resp;
    }
}